package ru.ifmo.genetics.factory.string;

import org.uncommons.watchmaker.framework.factories.AbstractCandidateFactory;

import java.util.List;
import java.util.Random;

/**
 * @author avhaliullin
 */
public class AlternativeStringFactory extends AbstractCandidateFactory<String> {
    private final int maxLen;
    private final int minLen;
    private final List<Character> alphabet;

    public AlternativeStringFactory(int minLen, int maxLen, List<Character> alphabet) {
        this.maxLen = maxLen;
        this.minLen = minLen;
        this.alphabet = alphabet;
    }

    public String generateRandomCandidate(Random rng) {
        int len = rng.nextInt(maxLen - minLen + 1) + minLen;
        StringBuilder res = new StringBuilder();
        for (int i = 0; i < len; i++) {
            res.append(alphabet.get(rng.nextInt(alphabet.size())));
        }
        return res.toString();
    }
}
